IF Statement Worksheet

Question 1

Why is an IF statement known as a control structure?

It dictates the flow of execution within a program.

Question 2

There are other control structures in JavaScript that we'll be learning about soon. Use your google skills to look up the other control structures in JavaScript and list them below.

Conditional Statements (if, else if, else, switch), Looping Statements (for, while, do...while), and Jump Statements (break, continue, return).

Question 3

What is a boolean expression?

A logical statement that evaluates to either true or false.

Question 4

What is the 'equality operator', and what is it used for? How is it different from the assignment operator?

The '==' is the so-called equality comparison operator and is used to check whether the two expressions on both sides are equal or not. The assignment operator '=' is used to assign a value to a variable.

Question 5

Why is it important to properly indent your code when writing IF statements?

Proper indentation improves code readability and helps to visually distinguish code blocks, making it easier to understand the structure and flow of the program.

Question 6

What is a code block in JavaScript?

A code block in JavaScript is a section of code that is grouped together within curly braces {}. It defines the scope of variables and functions and is commonly used in control structures like if statements, loops, and functions.

Question 7

What is a code block in JavaScript?


			let input = prompt("Are you a vegetarian (y/n)?");

			if(input == "y"){
				console.log("I recommend the pasta salad.");
			}else if(input == "n"){
				console.log("I recommend the prime rib");
			}
			
{ console.log("I recommend the pasta salad."); }else if(input == "n"){ console.log("I recommend the prime rib"); }

Coding Problems

Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.

Always test your work! Check the console log to make sure there are no errors.